import React, {Component} from 'react';
import {

} from 'react-native';

import DataManager from '../../datas/DataManager';
import Constants from '../../common/Constants';
import HeartLoveChatLinker from '../../datas/heart/HeartLoveChatLinker';
import IMOne2OneCommentPage from '../im/IMOne2OneCommentPage';
import HeartLoveChatItemView from './HeartLoveChatItemView';
import IMConstants from '../im/IMConstants';
import HeartLoveRquestOtherDataAction from '../../actions/heart/HeartLoveRquestOtherDataAction';

export default class HeartLoveChatPage extends IMOne2OneCommentPage {
  constructor(props) {
    super(props);

    this.state.loveData = {nick:"加载中"};
  }

  _dealEnterPage() {
    super._dealEnterPage();
    this.state.loveData = {nick:"加载中"};
  }

  _dealComponentWillUpdate(nextProps,nextState) {
    super._dealComponentWillUpdate(nextProps, nextState);

    if(nextState.loveData.lover_id != this.state.loveData.lover_id) {
      //因为要进行操作，所以先把值传过去
      this.state.loveData = nextState.loveData;
      this._initData();
    }
  }

  _initLinker() {
    if(this.state.loveData.lover_id != undefined) {
      this._linker = DataManager.callMethod(Constants.MODULE_TYPE.IM, "getLinker",
        [IMConstants.linkerType.one2one, this._getUserData().lover_id,
          HeartLoveChatLinker, {talkerData:this._getUserData(),
          linkerType:IMConstants.linkerType.one2one}]);
      this._linker.init({sendMessageCall:this._sendMessageCall.bind(this),
        updateCall:this._onLinkerUpdateCall.bind(this)});
    }
  }

  _requestUserData() {
    new HeartLoveRquestOtherDataAction().call(this, {lover_id:this.props.pageData.routeData.msguser_id})
  }

  _getTitle() {
    return this.state.loveData.nick;
  }

  _getUserData() {
    return this.state.loveData;
  }

  _dealRenderItem(data, index) {
    return <HeartLoveChatItemView data={data} selfData={this.props.pageData.routeData.userData}
      userData={this._getUserData()} index={index}
      ref={(ref) => this._itemViewRefs[index] = ref}/>
  }
}
